using System;
using ebcpatterns.flow;
using NUnit.Framework;

namespace ebcpatterns.tests.flow
{
    [TestFixture]
    public class MapTests
    {
        [Test]
        public void Extract_from_Tuple() {
            var map = new Map<Tuple<string, int>, string>(x => x.Item1);
            var result = "";
            map.Output += x => result = x;

            map.Input(new Tuple<string, int>("A", 42));

            Assert.That(result, Is.EqualTo("A"));
        }

        [Test]
        public void Map_to_void() {
            var map = new Map<string[]>();
            var count = 0;
            map.Output += () => count++;

            map.Input(new[]{"a"});

            Assert.That(count, Is.EqualTo(1));
        }

        [Test]
        public void Map_by_convention_if_target_properties_differ_by_type() {
            var map = new Map<Tuple<string, int>, int>();
            var result = 0;
            map.Output += x => result = x;

            map.Input(new Tuple<string, int>("x", 42));

            Assert.That(result, Is.EqualTo(42));
        }

        [Test]
        public void Map_by_convention_if_target_properties_have_same_type() {
            var map = new Map<Tuple<string, string>, string>();
            var result = "";
            map.Output += x => result = x;

            map.Input(new Tuple<string, string>("x", "y"));

            Assert.That(result, Is.EqualTo("x"));
        }
    }
}